package com.pxene.dmp.constant;

import java.io.InputStreamReader;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;

public class PatternList {

	private static final String FILE_PATH = "/pattern/";
	private static Gson gson = new Gson();
	private Pattern[] patterns;

	private PatternList(Pattern[] patterns) {
		this.patterns = patterns;
	}

	public static PatternList load(String fileName) {
		return new PatternList((Pattern[]) gson.fromJson(
				new JsonReader(new InputStreamReader(PatternList.class
						.getResourceAsStream(FILE_PATH + fileName))),
				Pattern[].class));
	}

	public Pattern[] elements() {
		return patterns;
	}

	public class Pattern {
		private String code;
		private String regex;
		private Param[] params;

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getRegex() {
			return regex;
		}

		public void setRegex(String regex) {
			this.regex = regex;
		}

		public Param[] getParams() {
			return params;
		}

		public void setParams(Param[] params) {
			this.params = params;
		}
	}

	public class Param {
		private String id;
		private String expr;

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}


		public String getExpr() {
			return expr;
		}

		public void setExpr(String expr) {
			this.expr = expr;
		}
	}

}
